package com.lyx.user.controller;


import com.lyx.common.result.R;
import com.lyx.common.result.Result;
import com.lyx.common.result.ResultUtil;
import com.lyx.user.dto.WxLoginDto;
import com.lyx.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 手机验证码登录
 * @author 14667
 * @date 2022/7/18 20:50
 */
@Controller
@RequestMapping("/phone")
public class LoginController {
    @Autowired
    public UserService userService;

    /**
     * 登录
     * @param phone
     * @param code
     * @return
     */
    @PostMapping("/login")
    @ResponseBody
    public R login(@RequestParam() String phone, @RequestParam String code) {
        WxLoginDto data = userService.login(phone,code);
        return R.ok().data("data",data);
    }

    /**
     * 退出登录
     * @param request
     * @return
     */
    @GetMapping("/logout")
    @ResponseBody
    public R logout(HttpServletRequest request){
        userService.logout(request);
        return R.ok().message("退出成功");
    }
}
